#include"stdafx.h"
#include "EditProcess.h"

int EditProcess::getOldTaskNo(){
	istringstream cmd(commandString);
	int result;
	cmd >> result;
	return result;
}

string EditProcess::getNewTask(){
	istringstream cmd(commandString);
	int temp;
	string result;

	cmd >> temp;
	cmd >> result;
	getline(cmd,result);
	string::iterator it;
	it = result.begin(); 
	result.erase(it);

	return result;
}

Task EditProcess::retrieveTask(int taskNo){
	Task result;
	needList->retrieve(taskNo,result);

	return result;
}

void EditProcess::backupToUndo(Task oldTask,Task newTask){
	taskContainer contain=upcoming;
	commandType type;
	
	type = Add;
	pushToUndoList(oldTask,type,contain,false);

	type=Delete;
	pushToUndoList(newTask,type,contain,true);
}

EditProcess::EditProcess(string command,allTaskList *givenLists,allCommandStack *givenStacks):LogicProcess(command,givenLists,givenStacks){
	needList=&allTask->getUpcomingTasks();
}

EditProcess::~EditProcess(){
}

void EditProcess::HandleProcesss(){
	int oldTaskNo = getOldTaskNo();
	string newTask = getNewTask();

	Task oldTask = retrieveTask(oldTaskNo);
	DeleteProcess deleted(oldTask,needList);
	deleted.quickProcess(oldTask);

	AddProcess added(newTask,allTask,prevCmds);
	added.solveContent();
	Task newFullTask = added.getFullTask();
	added.quickProcess(newFullTask);

	backupToUndo(oldTask,newFullTask);
	fromNeedtoDisplay();
}

void EditProcess::quickProcess(Task task){
}